<?php
// +----------------------------------------------------------------------
// | Yotaku shop
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.yotaku.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Creatint <creatint@163.com> <http://creatint.yotaku.cn>
// +----------------------------------------------------------------------
namespace Common\Api;
class ConfigApi {

    /**
     * @describe 获取配置数组，用于C方法扩展配置
     * @author Creatint
     * @param array $param
     * @return mixed
     */
    public static function getConfigLists($param = array()){
        $Config =   D("Config");
        $param  =   $param?:array('status'=>1);
        $result =   $Config->lists($param);
        $config =   array();
        if(is_array($result)){
            foreach($result as $v){
                $config[$v['name']] =   self::parse($v);
            }
        }

        return $config;
    }

    private static function parse($value){
        switch($value['type']){
            case 0:
                return (int)$value['value'];
            case 1:
            case 2:
                return (string)$value['value'];
            case 3:
            case 4:
                return json_decode($value['value']);
            default:
                trace("配置数组为空,文件：" . __FILE__ . "  行号：" . __LINE__ , "配置项",'debug',true);
                return;
        }
    }
}